package graphicinterface;

import java.awt.Image;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import bookworm.Book;



public class CreatesImageIcon 
{
	public static ImageIcon createImageIcon(String address, String description) 
	{
		address = address.toLowerCase();
		java.net.URL urlImage = Book.class.getResource(address);
		if(urlImage != null)
		{
			return new ImageIcon(Book.class.getResource(address), description);
		}
		else
		{
			JOptionPane.showMessageDialog(null, "image not found:" + address);
			return null;
		}
	}
	
	public static ImageIcon createImageIconFromUrl(String address, String description)
	{
		Image image = null;
        try {
            URL url = new URL(address);
            image = ImageIO.read(url);
            return new ImageIcon(image, description);
        } 
        catch (IOException e) 
        {
        	//JOptionPane.showMessageDialog(null, "image not found in URL:" + address);
			return null;
        }
	}

}
